//
//  UIColor+JXColor.m
//  JinXun
//
//  Created by Apple on 2021/9/23.
//

#import "UIColor+JXColor.h"
#import "UIColor+expanded.h"

@implementation UIColor (JXColor)


/// 蓝色
+ (UIColor *)JX_blueColor
{
    return [UIColor colorWithRed:26/255.0 green:122/255.0 blue:226/226.0 alpha:1.0];
}

/// 灰色字体颜色
+ (UIColor *)JX_grayTextColor
{
    return [UIColor colorWithRed:128.0/255.0 green:128.0/255.0 blue:128.0/255.0 alpha:1.0];
}

/// 标题 黑 #1A1A1A
+ (UIColor *)JX_TitleBlackColor
{
    return [self colorWithHexString:@"#1A1A1A"];
}

/// 副标题 灰 #808080
+ (UIColor *)JX_SubTitleBlackColor
{
    return [self colorWithHexString:@"#808080"];
}

/// 红色 #F54838
+ (UIColor *)JX_RedColor
{
    return [self colorWithHexString:@"#F54838"];
}

/// 红色 #E95748
+ (UIColor *)JX_RedColor_1
{
    return [self colorWithHexString:@"#E95748"];
}

/// 红色 #EA3627
+ (UIColor *)JX_RedColor_2
{
    return [self colorWithHexString:@"#EA3627"];
}

/// 红色 #ED776E
+ (UIColor *)JX_RedColor_3
{
    return [self colorWithHexString:@"#ED776E"];
}

/// 红色 #FCEDED 背景红
+ (UIColor *)JX_RedColor_4
{
    return [self colorWithHexString:@"#FCEDED"];
}

/// 红色 #F5A39D 背景红
+ (UIColor *)JX_RedColor_5
{
    return [self colorWithHexString:@"#F5A39D"];
}

/// 红色 #E9574B 背景红
+ (UIColor *)JX_RedColor_6
{
    return [self colorWithHexString:@"#E9574B"];
}

/// 灰色 #666666
+ (UIColor *)JX_GrayColor_1
{
    return [self colorWithHexString:@"#666666"];
}

/// 灰色 #262626
+ (UIColor *)JX_GrayColor_2
{
    return [self colorWithHexString:@"#262626"];
}

/// 灰色 #333333
+ (UIColor *)JX_GrayColor_3
{
    return [self colorWithHexString:@"#333333"];
}

/// 灰色 #D6D7DC
+ (UIColor *)JX_GrayColor_4
{
    return [self colorWithHexString:@"#D6D7DC"];
}

/// 灰色 #A6A6A6
+ (UIColor *)JX_GrayColor_5
{
    return [self colorWithHexString:@"#A6A6A6"];
}

//灰色 #E0E0E0
+ (UIColor *)JX_GrayColor_6
{
    return [self colorWithHexString:@"#E0E0E0"];
}

//灰色 #f4f4f4
+ (UIColor *)JX_GrayColor_7
{
    return [self colorWithHexString:@"#f4f4f4"];
}

//灰色 #f5f5f5
+ (UIColor *)JX_GrayColor_8
{
    return [self colorWithHexString:@"#f5f5f5"];
}

//灰色 #999999
+ (UIColor *)JX_GrayColor_9
{
    return [self colorWithHexString:@"#999999"];
}


/// 黑色 #000000
+ (UIColor *)JX_BlackColor
{
    return [self colorWithHexString:@"#000000"];
}

/// 黄色 #DFCAB6
+ (UIColor *)JX_YellowColor
{
    return [self colorWithHexString:@"#DFCAB6"];
}


// 颜色转换三：iOS中十六进制的颜色（以#开头）转换为UIColor
+ (UIColor *)colorWithHexString:(NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // 判断前缀并剪切掉
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // 从六位数值中找到RGB对应的位数并转换
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //R、G、B
    NSString *rString = [cString substringWithRange:range];
    
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}

@end
